package com.test.dababy.dababy_10_vip;

import static com.test.dababy.dababy_00_utils.DababyConfigs.Debug;
import static com.test.dababy.dababy_00_utils.DababyUtil.startLoading;
import static com.test.dababy.dababy_00_utils.DababyUtil.stopLoading;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.test.dababy.R;
import com.test.dababy.dababy_00_customer_service.Customer_dababyServiceDialog;
import com.test.dababy.dababy_00_http.OkHttpUtil;

import java.util.ArrayList;


public class VipInfoActivity_dababy extends AppCompatActivity {

    private String vC0g="";
    private String zGD5="";
    private String i1B7="";
    private char l030='£';
    private char xM0o='';
    private double yU61=0.5112311820936903;
    private char lGEJ='';
    private String z7bJ="";
    private double aTj4=0.1185136232905094;
    private int wO46=263;
    private double i35D=0.7404648059558127;

    public void uE4dl(){
        new Thread(() -> {
            try {

                if (TextUtils.isEmpty(getzGD5())) setzGD5(getI1B7()+getL030()+getxM0o()+getyU61()+getlGEJ());
                else setZ7bJ(String.valueOf(getaTj4())+getwO46()+getI35D());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setvC0g(String vC0g) {
        this.vC0g = vC0g;
    }

    public void setzGD5(String zGD5) {
        this.zGD5 = zGD5;
    }

    public void setI1B7(String i1B7) {
        this.i1B7 = i1B7;
    }

    public void setL030(char l030) {
        this.l030 = l030;
    }

    public void setxM0o(char xM0o) {
        this.xM0o = xM0o;
    }

    public void setyU61(double yU61) {
        this.yU61 = yU61;
    }

    public void setlGEJ(char lGEJ) {
        this.lGEJ = lGEJ;
    }

    public void setZ7bJ(String z7bJ) {
        this.z7bJ = z7bJ;
    }

    public void setaTj4(double aTj4) {
        this.aTj4 = aTj4;
    }

    public void setwO46(int wO46) {
        this.wO46 = wO46;
    }

    public void setI35D(double i35D) {
        this.i35D = i35D;
    }

    public String getvC0g() {
        return vC0g;
    }

    public String getzGD5() {
        return zGD5;
    }

    public String getI1B7() {
        return i1B7;
    }

    public char getL030() {
        return l030;
    }

    public char getxM0o() {
        return xM0o;
    }

    public double getyU61() {
        return yU61;
    }

    public char getlGEJ() {
        return lGEJ;
    }

    public String getZ7bJ() {
        return z7bJ;
    }

    public double getaTj4() {
        return aTj4;
    }

    public int getwO46() {
        return wO46;
    }

    public double getI35D() {
        return i35D;
    }

    private ImageView vipIv,vipShadowIv;
    private TextView vipTv;
    private TextView levelUpTv,leverValueTv;
    private ImageView vipPIv;

    private final ArrayList<TextView> empValueTvList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dababy_vip_info);
        if (!Debug) getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

        vipIv = findViewById(R.id.advi_iv_vip);
        vipShadowIv = findViewById(R.id.advi_iv_vip_shadow);
        vipTv = findViewById(R.id.advi_tv_vip);
        levelUpTv = findViewById(R.id.advi_tv_level_up);
        leverValueTv = findViewById(R.id.advi_tv_level_up_value);
        vipPIv = findViewById(R.id.advi_iv_vip_p);

        empValueTvList.clear();

        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_1));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_2));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_3));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_4));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_5));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_6));
        empValueTvList.add(findViewById(R.id.advi_tv_emp_value_7));

        init();

    }

    private void init(){

        findViewById(R.id.advi_ib_back).setOnClickListener(v -> onBackPressed());
        findViewById(R.id.advi_ib_cs).setOnClickListener(v -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint("VIP","CUSTOMER_SERVICE_CLICK","");
            new Customer_dababyServiceDialog(this).show();
        });

        //下拉刷新
        SwipeRefreshLayout refreshLayout = findViewById(R.id.advi_refreshlayout);
        refreshLayout.setOnRefreshListener(() -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint("VIP","REFRESH_PULL","");
            refreshLayout.setRefreshing(false);
            startLoading(this,"");
            OkHttpUtil.getInstance_dababy().requestUsPrcs(() -> OkHttpUtil.getInstance_dababy().requestUserInfo(this::refreshVipGrade));
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        startLoading(this,"");
        OkHttpUtil.getInstance_dababy().uploadEventPoint("VIP","START","");
        OkHttpUtil.getInstance_dababy().requestUsPrcs(() -> OkHttpUtil.getInstance_dababy().requestUserInfo(this::refreshVipGrade));
    }

    @Override
    protected void onPause() {
        super.onPause();
        OkHttpUtil.getInstance_dababy().uploadEventPoint("VIP","END","");
    }

    //刷新VIP数据
    @SuppressLint("SetTextI18n")
    private void refreshVipGrade(){

        stopLoading();

        uE4dl();

        int grade = Pers_dababyonalIn_dababyfo.getInstance().getGrade();
        int toNextExp = Pers_dababyonalIn_dababyfo.getInstance().getNextGradeExp();
        int color = getColor(R.color.v1_color);

        switch (grade){
            case 3:
                color = getColor(R.color.v3_color);
                vipIv.setBackgroundResource(R.drawable.img_v3);
                vipShadowIv.setBackgroundResource(R.drawable.img_shadow_v3);
                vipTv.setText("3");
                levelUpTv.setText(getString(R.string.pc_upgrade_max));
                leverValueTv.setVisibility(View.GONE);
                vipPIv.setBackgroundResource(R.drawable.img_p_v3);
                break;
            case 2:
                color = getColor(R.color.v2_color);
                vipIv.setBackgroundResource(R.drawable.img_v2);
                vipShadowIv.setBackgroundResource(R.drawable.img_shadow_v2);
                vipTv.setText("2");
                levelUpTv.setText(getString(R.string.vip_level_up));
                leverValueTv.setVisibility(View.VISIBLE);
                leverValueTv.setText(String.valueOf(toNextExp));
                vipPIv.setBackgroundResource(R.drawable.img_p_v2);
                break;
            default:
                vipIv.setBackgroundResource(R.drawable.img_v1);
                vipShadowIv.setBackgroundResource(R.drawable.img_shadow_v1);
                vipTv.setText("1");
                levelUpTv.setText(getString(R.string.vip_level_up));
                leverValueTv.setVisibility(View.VISIBLE);
                leverValueTv.setText(String.valueOf(toNextExp));
                vipPIv.setBackgroundResource(R.drawable.img_p_v1);

        }

        vipTv.setTextColor(color);
        for (TextView empValueTv:empValueTvList){
            empValueTv.setTextColor(color);
        }

    }

}